<template>
  <div style="height: auto">
    <!-- 头部搜索 -->
    <el-card style="width: 100%; margin-bottom: 10px" shadow="never">
      <el-row>
        <el-col :span="3">
          <el-select
            v-model="ordDto.orderType"
            placeholder="订单类型"
            style="width: 160px"
          >
            <el-option label="配送" value="1" />
            <el-option label="安装" value="2" />
          </el-select>
        </el-col>
        <el-col :span="3">
          <el-input
            v-model="ordDto.number"
            style="width: 200px"
            clerearable
            placeholder="销售订单"
          >
          </el-input>
        </el-col>

        <el-col :span="3">
          <el-input
            v-model="ordDto.number"
            style="width: 200px"
            clerearable
            placeholder="sams订单"
          >
          </el-input>
        </el-col>

        <el-col :span="3">
          <el-input
            v-model="ordDto.number"
            style="width: 200px"
            clerearable
            placeholder="送货订单"
          >
          </el-input>
        </el-col>

        <el-col :span="3">
          <el-input
            v-model="ordDto.ordernumber"
            style="width: 200px"
            placeholder="销售订单"
            clearable
          >
          </el-input>
        </el-col>
        <el-col :span="3">
          <el-input
            v-model="ordDto.date"
            style="width: 200px"
            clearable
            placeholder="预约时间"
          />
        </el-col>
        <el-col :span="3">
          <el-input
            v-model="ordDto.name"
            style="width: 200px"
            clearable
            placeholder="客户名称"
          />
        </el-col>

        <el-col :span="3">
          <el-input
            v-model="ordDto.phone"
            style="width: 200px"
            clearable
            placeholder="客户电话"
          />
        </el-col>

        <el-col
          style="display: flex; justify-content: flex-end; align-items: center"
          :span="2"
        >
          <el-space :size="20">
            <el-button type="primary" size="small" @click="handleSearch"
              >搜索</el-button
            >
            <el-button type="danger" size="small">重置</el-button>
          </el-space>
        </el-col>
      </el-row>
    </el-card>

    <!-- 表格数据展示 EEF7FD -->
    <el-card style="width: 100%; background: #eef7fd" shadow="never">
      <el-table
        :data="tableData"
        border
        v-loading="loading"
        style="width: 100%"
      >
        <el-table-column label="序号" width="60" align="center">
          <template #default="scope">
            {{ scope.$index + 1 }}
          </template>
        </el-table-column>

        <!-- <el-table-column prop="id" label="时段" width="50" align="center" /> -->

        <el-table-column
          prop="number"
          label="送货单号"
          width="100"
          align="center"
        >
          <template #default="scope">
            {{ scope.row.number }}
          </template>
        </el-table-column>

        
        <el-table-column
          prop="number"
          label="销售单号"
          width="100"
          align="center"
        >
          <template #default="scope">
            {{ scope.row.orderNumber }}
          </template>
        </el-table-column>

        <el-table-column
          prop="orderType"
          label="订单类型"
          align="center"
          width="100"
        >
          <template #default="scope">
            {{ scope.row.orderType == 1 ? "配送" : "安装" }}
          </template>
        </el-table-column>

        <el-table-column
          prop="periodsTime"
          label="时段"
          align="center"
          width="120"
        >
        <template #default="scope">
          {{ scope.row.reservation}} ({{ scope.row.periods }})
          </template>
      </el-table-column>
        <!-- <el-table-column
          prop="period"
          label="时段"
          width="50"
          align="center"
        /> -->

        <el-table-column
          prop="name"
          label="客户名称"
          width="150"
          align="center"
        />
        <el-table-column
          prop="phone"
          label="联系电话"
          width="150"
          align="center"
        />
        <el-table-column prop="address" label="地址" align="center" />
        <el-table-column
          prop="storeBUCode"
          label="购买商店"
          align="center"
          width="60"
        ></el-table-column>
        <el-table-column
          prop="senderBuCode"
          label="发货商店"
          align="center"
          width="60"
        ></el-table-column>
        <el-table-column
          prop="optional"
          label="自选件数"
          align="center"
          width="60"
        />
        <el-table-column
          prop="sidestorage"
          label="内仓件数"
          align="center"
          width="60"
        />
        <el-table-column
          prop="outsidestorage"
          label="外仓订单号"
          align="center"
          width="80"
        >
        </el-table-column>

        <el-table-column prop="code" label="检验码" align="center" width="60" />
        <el-table-column
          prop="centiorstate"
          label="状态"
          width="80"
          align="center"
        />
        <el-table-column
          prop="centiorstate"
          label="服务状态"
          width="80"
          align="center"
        />
        <el-table-column
          prop="createTime"
          label="状态"
          width="120"
          align="center"
        />
        <el-table-column label="操作" align="center" width="80">
          <template #default="scope">
            <el-button
              type="primary"
              size="small"
              v-has="`btn:user:per:role`"
              @click="handleRole(scope.row)"
            >
              查看
            </el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <div style="margin-top: 10px; text-align: center">
        <el-pagination
          :current-page="pageNo"
          :page-size="pageSize"
          :page-sizes="[10, 20, 30, 50]"
          :small="small"
          :disabled="disabled"
          layout="total,prev, pager, next,sizes,jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </el-card>
  </div>
</template>
  
  <script setup>
import { ref, onMounted } from "vue";
import { useRouter } from "vue-router";
import { findikeaAllOrderMsg } from "@/api/order";
import { ElLoading } from "element-plus";
import { ElMessage } from "element-plus";
const small = ref("small");
const loading = ref(false);
const tableData = ref([]);
const pageNo = ref(1);
const pageSize = ref(20);
const total = ref(0);
const disabled = ref(false);

const router = useRouter();

const ordDto = ref({
  pageIndex: 0,
  pageSize: 10,
  number: "",
  phone: "",
  name: "",
  ordernumber: "",
  date: "",
  end: "",
  orderType: "",
});

onMounted(() => {
  getList();
});

const handleSizeChange = () => {
  ordDto.value.pageSize = pageSize.value;
  getList();
};
const handleCurrentChange = (e) => {
  console.log(e);
  // pageNo.value = e == 1 ? 1 : pageNo.value + 1;
  // ordDto.value.pageIndex = pageNo.value - 1;
  pageNo.value = e;
  ordDto.value.pageIndex = e;
  getList();
};

const getList = () => {
  loading.value = true;
  findikeaAllOrderMsg(ordDto.value)
    .then((res) => {
      console.log(res);
      loading.value = false;
      if (res.code === 200 && res.data !== null) {
        tableData.value = res.data.data;
        tableData.value.filter((item) => {
          item.createTime = formatIsoDate(item.createTime);
        });
        total.value = res.data.total;
      }
    })
    .catch((err) => {
      loading.value = false;
      ElMessage.error(err.message);
      console.log(err.message);
    });
};

const formatIsoDate = (isoDateString) => {
  const date = new Date(isoDateString);

  // 格式化日期部分 YYYY-MM-DD
  const year = date.getFullYear();
  const month = String(date.getMonth() + 1).padStart(2, "0");
  const day = String(date.getDate()).padStart(2, "0");

  // 格式化时间部分 HH:MM:SS
  const hours = String(date.getHours()).padStart(2, "0");
  const minutes = String(date.getMinutes()).padStart(2, "0");
  const seconds = String(date.getSeconds()).padStart(2, "0");

  // 组合成目标格式
  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
};
const handleSearch = (obj) => {
  getList();
};

const handleRole = (obj) => {
  console.log(obj.number);

  router.push({ path: "/topic/details", query: { id: obj.id } });

  //router.push({ path: "/topic/details", query: { id: 2789318275056 } });
  // router.push({ name: "details", query: { id: obj.number } });
};
</script>
<style scoped>
/*最外层透明*/
::v-deep .el-table,
::v-deep .el-table__expanded-cell {
  background-color: transparent !important;
}
/* 表格内背景颜色 */
::v-deep .el-table th,
::v-deep .el-table tr,
::v-deep .el-table td {
  background-color: transparent !important;
  border: 0;
  color: #135294;
}
/*去除底边框*/
::v-deep.el-table td.el-table__cell {
  border: 0;
}
::v-deep.el-table th.el-table__cell.is-leaf {
  border: 0;
}
/*去除底部灰条.el-table::before*/
::v-deep .el-table::before {
  display: none;
}
.el-pagination {
  text-align: center;
  justify-content: center;
  color: #135294;
}
::v-deep .el-pagination__sizes,
.el-pagination__total {
  color: #135294 !important;
}
::v-deep .el-pagination button {
  background-color: transparent !important;
}
::v-deep .el-pager li {
  background-color: transparent !important;
}
::v-deep .el-pagination button.is-disabled,
.el-pagination button:disabled {
  background-color: transparent !important;
}
::v-deep .el-pagination .el-select {
  width: 100px !important;
}
</style>